package com.jihui.user.service.impl;

import com.jihui.user.dao.UserDao;
import com.jihui.user.model.JihuiUser;
import com.jihui.user.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * Created by wangjin on 2017/5/19.
 */
@Service
public class UserServiceImpl implements UserService {
    private final static Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Autowired
    private UserDao userDao;
    @Override
    public void sayHello(String name) {
         userDao.sayHello(name);
    }

    @Override
    public void save(JihuiUser jihuiUser) {
        userDao.save(jihuiUser);
    }

    @Override
    public JihuiUser login(String userName, String password, String ip) throws Exception {
        JihuiUser jihuiUser = userDao.findByUsername(userName);
        if (jihuiUser == null) {
            logger.error("无此用户");
            throw new Exception("Y20-100404");
        }
        if(!password.equals(jihuiUser.getPassword())){
            logger.error("密码错误");
            throw new Exception("Y20-100404");
        }
        return jihuiUser;
    }

}
